/**
 * Copyright (c) 2006-2016 Huize Ltd. All Rights Reserved. 
 *  
 * This code is the confidential and proprietary information of   
 * Hzins. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with Huize,http://www.huize.com.
 *  
 */
package com.agan.concurrent;

import java.math.BigInteger;
import java.util.concurrent.BlockingQueue;

/**
 * @author hz1412988
 * @date 2018年2月8日 下午5:01:37
 * @version
 */
public class PrimeProducer extends Thread {

    private final BlockingQueue<BigInteger> queue;

    PrimeProducer(BlockingQueue<BigInteger> queue) {
	this.queue = queue;
    }

    public void run() {
	try {
	    BigInteger p = BigInteger.ONE;
	    while (!Thread.currentThread().isInterrupted())
		queue.put(p = p.nextProbablePrime());
	} catch (InterruptedException consumed) {
	    /* Allow thread to exit */
	}
    }

    public void cancel() {
	interrupt();
    }
}
